package com.zillion.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zillion.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zillion.common.annotation.Log;
import com.zillion.common.core.controller.BaseController;
import com.zillion.common.core.domain.AjaxResult;
import com.zillion.common.enums.BusinessType;
import com.zillion.system.domain.HealthHoliday;
import com.zillion.system.service.IHealthHolidayService;
import com.zillion.common.utils.poi.ExcelUtil;
import com.zillion.common.core.page.TableDataInfo;

/**
 * 法定节假日Controller
 * 
 * @author zillion
 * @date 2025-10-09
 */
@RestController
@RequestMapping("/system/holiday")
public class HealthHolidayController extends BaseController
{
    @Autowired
    private IHealthHolidayService healthHolidayService;

    /**
     * 查询法定节假日列表
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthHoliday healthHoliday)
    {
        startPage();
        List<HealthHoliday> list = healthHolidayService.selectHealthHolidayList(healthHoliday);
        return getDataTable(list);
    }

    /**
     * 导出法定节假日列表
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:export')")
    @Log(title = "法定节假日", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthHoliday healthHoliday)
    {
        List<HealthHoliday> list = healthHolidayService.selectHealthHolidayList(healthHoliday);
        ExcelUtil<HealthHoliday> util = new ExcelUtil<HealthHoliday>(HealthHoliday.class);
        util.exportExcel(response, list, "法定节假日数据");
    }

    /**
     * 获取法定节假日详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(healthHolidayService.selectHealthHolidayById(id));
    }

    /**
     * 获取法定节假日
     */
//    @PreAuthorize("@ss.hasPermi('system:holiday:query')")
    @Anonymous
    @GetMapping("/getHoliday/{year}")
    public AjaxResult getHoliday(@PathVariable("year") String year)
    {
        return success(healthHolidayService.getHoliday(year));
    }

    /**
     * 获取节假日补班
     */
//    @PreAuthorize("@ss.hasPermi('system:holiday:query')")
    @Anonymous
    @GetMapping("/getWorkday/{year}")
    public AjaxResult getWorkday(@PathVariable("year") String year)
    {
        return success(healthHolidayService.getWorkday(year));
    }

    /**
     * 新增法定节假日
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:add')")
    @Log(title = "法定节假日", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthHoliday healthHoliday)
    {
        return toAjax(healthHolidayService.insertHealthHoliday(healthHoliday));
    }

    /**
     * 修改法定节假日
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:edit')")
    @Log(title = "法定节假日", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthHoliday healthHoliday)
    {
        return toAjax(healthHolidayService.updateHealthHoliday(healthHoliday));
    }

    /**
     * 删除法定节假日
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:remove')")
    @Log(title = "法定节假日", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthHolidayService.deleteHealthHolidayByIds(ids));
    }
}
